<template>
  <div>
    <van-field label="添加分类" v-model="name"/>
    <van-field label="添加参数" v-model="params"/>
    <van-button @click="add_cate">确定添加</van-button>
    <p>无限极分类</p>
    <reply :data="cates"/>


  </div>
</template>

<script>
import reply from "./reply";

export default {
  name: "cate",
  data() {
    return {
      pid: 0,
      name: '',
      params: '',
      cates:{}
    }
  },
  components:{
    'reply':reply
  },
  methods: {
    //添加分类
    add_cate() {
      if (this.params) {
        this.params = JSON.stringify(this.params)
      }
      if(localStorage.getItem('pid')){
        this.pid = localStorage.getItem('pid')
      }
      let data = {'name': this.name, 'pid': this.pid, 'params': this.params}
      this.$axios.post('users/cateM', data).then(res => {
        if (res.data.code == 200) {
          alert('ok')
          localStorage.removeItem('pid')
          this.getlist()
        } else {
          alert('no')
        }
      })
    },


    //获取无限极分类
    getlist(){
      this.$axios.get('users/cateM').then(res=>{
        this.cates = {'id':0,'name':'333','son':res.data.list}
      })
    }
  },
  mounted() {
    this.getlist()
  }
}
</script>

<style scoped>

</style>
